fix(Power): refactor EXT_CHRG_DETECT to compile-time macros with pull-mode inference#10191
Merged
jp-bennett merged 2 commits intomeshtastic:developfrom Apr 23, 2026
Merged
Conversation
Contributor
Author
|
I’m going to drop the 2nd commit to prevent potential regressions and reduce the scope of the PR. |
Mirror the EXT_PWR_DETECT pattern: replace runtime static variables (ext_chrg_detect_mode, ext_chrg_detect_value) with compile-time macros. Auto-infer EXT_CHRG_DETECT_VALUE from EXT_CHRG_DETECT_MODE when the mode is INPUT_PULLUP (→ LOW) or INPUT_PULLDOWN (→ HIGH); default to HIGH. This fixes inverted polarity on variants that define EXT_CHRG_DETECT_MODE INPUT_PULLUP without an explicit EXT_CHRG_DETECT_VALUE (e.g. russell): previously the runtime default of HIGH caused isCharging() to return the opposite of the correct value. With auto-inference the correct LOW active level is now derived at compile time. Remove the now-redundant EXT_CHRG_DETECT_VALUE HIGH from ELECROW-ThinkNode-M4 variant.h since HIGH is the inferred default. Signed-off-by: Andrew Yong <noreply@example.com> Assisted-by: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Author
|
Commit dropped and rebased on develop |
Collaborator
|
I started working on Power.cpp, and found myself making exactly these changes. =D Will pull so you get credit. |
Contributor
Author
|
Cheers. Not fussy myself. Whichever outcome is easier for the project.
…On Fri, Apr 24, 2026 at 01:11 Jonathan Bennett ***@***.***> wrote:
*jp-bennett* left a comment (meshtastic/firmware#10191)
<#10191?email_source=notifications&email_token=AACAFAA7NPTAEXKSHPQUWQT4XJMFJA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIMZQGY3TCMBUGM22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2LK4DSL5RW63LNMVXHIX3POBSW4X3DNRUWG2Y#issuecomment-4306710435>
I started working on Power.cpp, and found myself making exactly these
changes. =D Will pull so you get credit.
—
Reply to this email directly, view it on GitHub
<#10191?email_source=notifications&email_token=AACAFAA7NPTAEXKSHPQUWQT4XJMFJA5CNFSNUABFM5UWIORPF5TWS5BNNB2WEL2JONZXKZKDN5WW2ZLOOQXTIMZQGY3TCMBUGM22M4TFMFZW63VGMF2XI2DPOKSWK5TFNZ2LK4DSL5RW63LNMVXHIX3POBSW4X3DNRUWG2Y#issuecomment-4306710435>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACAFACECGJOZSM6WTWCXXL4XJMFJAVCNFSM6AAAAACX4O6XOGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DGMBWG4YTANBTGU>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Mirrors the
EXT_PWR_DETECTpattern: replaces runtimestaticvariables (ext_chrg_detect_mode,ext_chrg_detect_value) with compile-time macros.Auto-infers
EXT_CHRG_DETECT_VALUEfromEXT_CHRG_DETECT_MODEat compile time:INPUT_PULLUP→LOWINPUT_PULLDOWN→HIGHHIGHThis fixes inverted polarity on variants that define
EXT_CHRG_DETECT_MODE INPUT_PULLUPwithout an explicitEXT_CHRG_DETECT_VALUE(e.g. russell): the old runtime default ofHIGHcausedisCharging()to return the wrong value.Variants touched:
INPUT_PULLUPnow correctly infersLOWEXT_CHRG_DETECT_VALUE HIGHremoved; behaviour unchanged (HIGH is the inferred default)🤝 Attestations
pio run -e tracker-t1000-eSUCCESS; explicitEXT_CHRG_DETECT_VALUE LOWpreserved, gate now also applies (CHARGER_DET gates CHARGE_STA — semantically correct)pio run -e rak3172SUCCESS (noEXT_CHRG_DETECT, confirms no regression);pio run -e russellSUCCESS (INPUT_PULLUP auto-inference + gate verified)